<?php

namespace app\common\model\room\department;

use app\common\enum\DefaultEnum;
use app\common\model\BaseModel;
use app\common\model\Building;
use app\common\model\Campus;
use think\model\concern\SoftDelete;

/**
 * 科室房间管理模型
 * Class RoomDepartment
 * @package app\common\model\room
 */
class RoomDepartment extends BaseModel {

    use SoftDelete;

    protected $deleteTime = 'delete_time';
    protected $name = 'room_department';


    public function campus() {
        return $this->hasOne(Campus::class, 'id', 'cid')->field('id,name');
    }

    public function building() {
        return $this->hasOne(Building::class, 'id', 'bid');
    }

    public function departmentItem() {
        return $this->hasOne(Department::class, 'id', 'department_id')->field('id,name');
    }

    public function allDevice() {
        return $this->hasMany(RoomDepartmentDevice::class, 'rid', 'id');
    }

    protected $append = ['sort', 'status_text'];

    public function getNoAppendAttr($value, $data) {
        return "";
    }

    public function getSortAttr($value, $item) {
        return $this->handle_sort($item['sort']);
    }

    public function getStatusTextAttr($value, $data) {
        return DefaultEnum::getShowDesc($data['status']);
    }

    public function getPrintKeywordListRoomStat() {
        return [
            "code" => "科室代码",
            "name" => "科室名",
            "room_d_use_total" => "用电度数",
            "room_d_total_fee" => "电费",
            "room_s_use_total" => "用水度数",
            "room_s_total_fee" => "水费",
            "log_date" => "日期",
        ];
    }

    public function getPrintKeywordListRoom() {
        return [
            "index" => "序号",
            "name" => "科室名",
            "code" => "科室代码",

//            "d_base_number" => "电表底数",
//            "d_reading" => "电表读数",
            "room_d_use_total" => "用电度数",
            "room_d_price" => "电单价",
            "room_d_total_fee" => "电费",

//            "s_base_number" => "水表底数",
//            "s_reading" => "水表读数",
            "room_s_use_total" => "用水度数",
            "room_s_price" => "水单价",
            "room_s_total_fee" => "水费",

            "log_date" => "月份",
        ];
    }

}

